package com.jason.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    private static final String SECKILL_QUEUE = "seckillQueue";
    private static final String SECKILL_EXCHANGE = "seckillExchange";

    @Bean("seckillQueue")
    public Queue seckillQueue(){
        return new Queue(SECKILL_QUEUE);
    }

    @Bean("seckillExchange")
    public TopicExchange topicExchange(){
        return new TopicExchange(SECKILL_EXCHANGE);
    }

    @Bean
    public Binding seckillBinding(@Qualifier("seckillQueue")Queue seckillQueue,
                                  @Qualifier("seckillExchange")TopicExchange seckillExchange){
        return BindingBuilder.bind(seckillQueue).to(seckillExchange).with("seckill.#");
    }
}
